package com.lanou.object;

import java.util.Objects;

public class Student implements Cloneable{
	private String name;
	private Clazz clazz;
	
	
	public Student(String name) {
		super();
		this.name = name;
	}

	
	

	public Clazz getClazz() {
		return clazz;
	}




	public void setClazz(Clazz clazz) {
		this.clazz = clazz;
	}




	public Student(String name, Clazz clazz) {
		super();
		this.name = name;
		this.clazz = clazz;
	}




	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}

	

	

	@Override
	public int hashCode() {
		return Objects.hash(name);
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		return Objects.equals(name, other.name);
	}

	
	

	/**
	 * clone默认浅拷贝
	 * 实现深拷贝
	 */
//	@Override
//	public Student clone() throws CloneNotSupportedException {
//		Clazz clazz = new Clazz(new String(this.getClazz().getClazzNo()));
//		Student student = new Student(new String(this.getName()),clazz);
//		// TODO Auto-generated method stub
//		return student;
//		//return (Student)super.clone();
//	}
	
	
	@Override
	protected Student clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return (Student)super.clone();
	}


	public static void main(String[] args) throws CloneNotSupportedException {
		Clazz clazz = new Clazz("1111");
		Student student = new Student("张三",clazz);
		Student student2 = new Student("张三");
		System.out.println(student == student2);
		System.out.println(student.equals(student2));
		System.out.println(student.hashCode());
		System.out.println(student2.hashCode());
		//克隆对象
//		try {
//			
//			//Student s = new Student(student.name,student.clazz);
//			Student s = student.clone();
//			System.out.println(s.equals(student));
//			System.out.println(s.getClazz() == student.getClazz());
//		} catch (CloneNotSupportedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		Student s = student.clone();
		
		System.out.println(student);
		
		//
	}




	@Override
	public String toString() {
		return "Student [name=" + name + ", clazz=" + clazz + "]";
	}




	
	
	
	

}

class Clazz{
	private String clazzNo;
	
	

	public Clazz(String clazzNo) {
		super();
		this.clazzNo = clazzNo;
	}

	public String getClazzNo() {
		return clazzNo;
	}

	public void setClazzNo(String clazzNo) {
		this.clazzNo = clazzNo;
	}

	@Override
	public String toString() {
		return "Clazz [clazzNo=" + clazzNo + "]";
	}
	
	
	
	
}
